<template>
  <div class="echarts">
    <div ref="echartDivRef" :style="{ width: width, height: height }"></div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted, watchEffect } from "vue";

import * as echarts from "echarts"

import useEchart from '../hook/useEchart'

export default defineComponent({
  props: {
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "360px",
    },
    options: {
      type: Object,
      default: () => ({})
    }
  },
  setup(props) {
    const echartDivRef = ref<HTMLElement>();

    onMounted(() => {
      const { setOptions } = useEchart(echartDivRef.value!)
      
      watchEffect(() => {
        setOptions(props.options)
      })
    })

    return {
      echartDivRef,
    };
  },
});
</script>

<style scoped lang="less"></style>